//
//  UIs_Hugging_CompressionResistance_DemoVC.swift
//  APSwift
//
//  Created by jianbo.pei on 2023/10/10.
//

/**
 ## 参考链接：
 - [setContentHuggingPriority和setContentCompressionResistancePriority的使用](https://blog.csdn.net/u014600626/article/details/130789524)
 */

import UIKit
import APExtensions

class UIs_Hugging_CompressionResistance_DemoVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        view.backgroundColor = .white
        test1()
        test2()
        test3()
        test4()
    }
}

extension UIs_Hugging_CompressionResistance_DemoVC {
    fileprivate func test1() {
        let lb1 = UILabel().then { make in
            view.addSubview(make)
            make.backgroundColor = .red
            make.snp.makeConstraints { make in
                make.left.equalTo(15)
                make.top.equalTo(ap_kStatusHeight + 50)
            }
        }
        
        let lb2 = UILabel().then { make in
            view.addSubview(make)
            make.backgroundColor = .yellow
            make.snp.makeConstraints { make in
                make.right.equalTo(-15)
                make.top.equalTo(ap_kStatusHeight + 50)
            }
        }
        
        lb1.text = "同是天涯沦落人，相逢何必曾相识。"
        lb2.text = "白居易"
    }
    
    fileprivate func test2() {
        let lb1 = UILabel().then { make in
            view.addSubview(make)
            make.backgroundColor = .red
        }
        
        let lb2 = UILabel().then { make in
            view.addSubview(make)
            make.backgroundColor = .yellow
            make.snp.makeConstraints { make in
                make.right.equalTo(-15)
                make.top.equalTo(ap_kStatusHeight + 100)
            }
        }
        
        lb1.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.top.equalTo(ap_kStatusHeight + 100)
            make.right.equalTo(lb2.snp.left).offset(-8)
        }
        
        lb1.text = "同是天涯沦落人，相逢何必曾相识。"
        lb2.text = "『唐』白居易 《琵琶行》"
    }
    
    fileprivate func test3() {
        let lb1 = UILabel().then { make in
            view.addSubview(make)
            make.backgroundColor = .red
        }
        
        let lb2 = UILabel().then { make in
            view.addSubview(make)
            make.backgroundColor = .yellow
            make.snp.makeConstraints { make in
                make.right.equalTo(-15)
                make.top.equalTo(ap_kStatusHeight + 150)
            }
        }
        
        lb1.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.top.equalTo(ap_kStatusHeight + 150)
            make.right.equalTo(lb2.snp.left).offset(-8)
        }
//        lb1.setContentCompressionResistancePriority(.required, for: .horizontal)
        lb1.setContentHuggingPriority(.required, for: .horizontal)
        
        lb1.text = "同是天涯沦落人，相逢何必曾相识。"
        lb2.text = "『唐』白居易 《琵琶行》"
    }
    
    fileprivate func test4() {
        let lb1 = UILabel().then { make in
            view.addSubview(make)
            make.backgroundColor = .red
        }
        
        let lb2 = UILabel().then { make in
            view.addSubview(make)
            make.backgroundColor = .yellow
            make.snp.makeConstraints { make in
                make.right.equalTo(-15)
                make.top.equalTo(ap_kStatusHeight + 200)
            }
        }
        
        lb1.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.top.equalTo(ap_kStatusHeight + 200)
            make.right.equalTo(lb2.snp.left).offset(-8)
        }
        lb1.setContentHuggingPriority(.required, for: .horizontal)
        lb1.setContentCompressionResistancePriority(.required, for: .horizontal)
        
        lb1.text = "同是天涯沦落人，相逢何必曾相识。"
        lb2.text = "白居易"
    }
    
}
